//
//  HomeViewController.m
//  WisdomCommunity
//
//  Created by Yahaong on 16/7/22.
//  Copyright © 2016年 zonten. All rights reserved.
//

#import "CommunityController.h"
#import "UIBarButtonItem+Extension.h"
#import "YHLoopView.h"
#import "CommunityButtonsView.h"
#import "CommunityBottomView.h"
#import "PassportViewController.h"
#import "PropertycostsViewController.h"
#import "InteractiveViewController.h"
#import "VolunteerservViewController.h"
#import "ParkViewController.h"
#import "PensionViewController.h"
#import "NetViewController.h"
#import "YYImage.h"
#import "AudioToolbox/AudioToolbox.h"
#import "MeViewController.h"
#import "OpenDoorView.h"
#import "AnnouncementViewController.h"
#import "YHMarcros.h"
@interface CommunityController ()
<
CommunityButtonsViewDelegate,
CommunityBottomViewDelegate
>
@property (nonatomic, strong)YHLoopView *cycleLoopView;
@property (nonatomic, strong)CommunityButtonsView *buttonsView;
@property (nonatomic, strong)CommunityBottomView  *bottomView;
@property (nonatomic, strong)OpenDoorView *m_viewOpenDoor;

@end

@implementation CommunityController


#pragma mark - life
- (void)dealloc {
   debugLogInfo(@"CommunityController dealloc....");
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

#pragma mark - setup
- (void)initSubviews
{
    self.view.backgroundColor = kBgColor;
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self setupNavigationView];
    [self.view addSubview:self.cycleLoopView];
    [self.cycleLoopView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.equalTo(self.view);
        make.height.equalTo(kIphoneSize_Height(150));
    }];
    [self.view addSubview:self.buttonsView];
    [self.buttonsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.view);
        make.top.equalTo(self.cycleLoopView.bottom);
        make.height.equalTo(150);
    }];
    [self.view addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.view);
        make.top.equalTo(self.buttonsView.bottom).offset(kIphoneSize_Height(10));
        make.bottom.equalTo(self.view).offset(-kIphoneSize_Height(10));
    }];
}

- (void)setupNavigationView
{
    self.view.backgroundColor = kBgColor;
    self.navigationItem.title = @"智慧社区";
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem createBarbuttonItem:@"home_icon_me" target:self action:@selector(enterMeController)];
}

#pragma mark - event reponse
- (void)enterMeController
{
    MeViewController *meVc = [[MeViewController alloc]init];
    [self.navigationController pushViewController:meVc animated:YES];
}

#pragma mark - CommunityBottomViewDelegate
- (void)communityBottomViewDidClick:(CommunityBottomViewButtonType)buttonType
{
    switch (buttonType) {
        //预约就医
        case CommunityBottomViewButtonTypeDoctor:
        {
            NetViewController *netVc = [[NetViewController alloc]init];
            netVc.navigationItem.title = @"预约就医";
            netVc.url = [NSURL URLWithString:@"http://wap.91160.com/"];
            [self.navigationController pushViewController:netVc animated:YES];
        }
            break;
        //违规驾驶
        case CommunityBottomViewButtonTypeIllegaldriv:
        {
            NetViewController *netVc = [[NetViewController alloc]init];
            netVc.navigationItem.title = @"违规驾驶";
            netVc.url = [NSURL
                         URLWithString:@"http://wz.m.autohome.com.cn/"];
            [self.navigationController pushViewController:netVc animated:YES];
        }
            break;
        //快递服务
        case CommunityBottomViewButtonTypeDelivery:
        {
            NetViewController *netVc = [[NetViewController alloc]init];
            netVc.navigationItem.title = @"快递服务";
            netVc.url = [NSURL URLWithString:@"http://m.kuaidi100.com/"];
            [self.navigationController pushViewController:netVc animated:YES];
        }
            break;
        //最优购物
        case CommunityBottomViewButtonTypeShopping:
        {
            NetViewController *netVc = [[NetViewController alloc]init];
            netVc.navigationItem.title = @"最优购物";
            netVc.url = [NSURL URLWithString:@"https://chaoshi.m.tmall.com/"];
            [self.navigationController pushViewController:netVc animated:YES];
            
        }
            break;
        //闲置市场
        case CommunityBottomViewButtonTypeIdlemarket:
        {
            NetViewController *netVc = [[NetViewController alloc]init];
            netVc.navigationItem.title = @"最优购物";
            netVc.url = [NSURL URLWithString:@"http://m.58.com/cd/sale.shtml?reform=pcfront"];
            [self.navigationController pushViewController:netVc animated:YES];
        }
            break;
        default:
            break;
}   }
#pragma mark - CommunityButtonsViewDelegate
- (void)communityButtonsViewDidClick:(CommunityButtonsViewButtonType)buttonType
{
    switch (buttonType) {
        //开门
        case CommunityButtonsViewButtonTypeOpenDoor:
        {
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
            UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
            [window addSubview:self.m_viewOpenDoor];
            [self.m_viewOpenDoor mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(window);
            }];
            
        }
            break;
        //小区公告
        case CommunityButtonsViewButtonTypeAnnouncement:
        {
         
            AnnouncementViewController *announcementVc = [[AnnouncementViewController alloc]init];
            [self.navigationController pushViewController:announcementVc animated:YES];
            
        }
            break;
        //物业缴费
        case CommunityButtonsViewButtonTypePropertycosts:
        {
            PropertycostsViewController *propertycostsVc = [[PropertycostsViewController alloc]init];
            [self.navigationController pushViewController:propertycostsVc animated:YES];
        }
            break;
        //智能停车
        case CommunityButtonsViewButtonTypePark:
        {
            ParkViewController *parkVc = [[ParkViewController alloc]init];
            [self.navigationController pushViewController:parkVc animated:YES];
        }
            break;
        //访客通行
        case CommunityButtonsViewButtonTypePassport:
        {
            PassportViewController *passportVc = [[PassportViewController alloc]init];
            [self.navigationController pushViewController:passportVc animated:YES];
        }
            break;
   
        //邻里互动
        case CommunityButtonsViewButtonTypeInteractive:
        {
            InteractiveViewController *interactiveVc = [[InteractiveViewController alloc]init];
            [self.navigationController pushViewController:interactiveVc animated:YES];
        }
         break;
        // 志愿服务
        case CommunityButtonsViewButtonTypeVolunteerserv:
        {
            VolunteerservViewController *volunteerservVc = [[VolunteerservViewController alloc]init];
            [self.navigationController pushViewController:volunteerservVc animated:YES];
        }
            break;
        //智慧养老
        case CommunityButtonsViewButtonTypePension:
        {
            NetViewController *netVc = [[NetViewController alloc]init];
            netVc.navigationItem.title = @"智慧养老";
            netVc.url = [NSURL URLWithString:@"http://www.intengz.com/#"];
            [self.navigationController pushViewController:netVc animated:YES];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark -lazy loading
- (YHLoopView *)cycleLoopView
{
    if (!_cycleLoopView) {
        _cycleLoopView = [[YHLoopView alloc]init];
        _cycleLoopView.imageArray = @[@"community_icon_loop1", @"community_icon_loop2", @"community_icon_loop3"];
    }
    return _cycleLoopView;
}
- (CommunityButtonsView *)buttonsView
{
    if (!_buttonsView)
    {
        _buttonsView =[[ CommunityButtonsView alloc]init];
        _buttonsView.delegate = self;
    }
    return _buttonsView;
}

- (CommunityBottomView *)bottomView
{
    if (!_bottomView)
    {
        _bottomView = [[CommunityBottomView alloc]init];
        _bottomView.delegate = self;
    }
    return _bottomView;
}

- (OpenDoorView *)m_viewOpenDoor
{
    if (!_m_viewOpenDoor) {
        _m_viewOpenDoor = [[OpenDoorView alloc]init];
    }
    return _m_viewOpenDoor;
}
@end
